<?php
/*
jimport('infinity.log');
Log::_('file-name', $_POST, JLog::ERROR, 'POST');
*/
abstract class Log {
	public static function _($tag, $messages, $priority = JLog::INFO, $category = '')
	{
		jimport('joomla.log.log');
		JLog::addLogger(array(
			'text_entry_format' => "{DATETIME} {PRIORITY} {CATEGORY}-------------------------{MESSAGE}",
			'text_file' => $tag.'.'.date('Ymd').'.php'
			));

		// Check for proxies as well.
		$clientIP = '';
		if (isset($_SERVER['REMOTE_ADDR']))
		{
			$clientIP = $_SERVER['REMOTE_ADDR'];
		}
		elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
		{
			$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
		}
		elseif (isset($_SERVER['HTTP_CLIENT_IP']))
		{
			$clientIP = $_SERVER['HTTP_CLIENT_IP'];
		}

		$results = array(
			'IP' => $clientIP,
			'URL' => JFactory::getUri()->toString()
		);
		if(is_array($messages))
			$results['MESSAGE'] = print_r($messages, true);
		if(is_string($messages))
			$results['MESSAGE'] = $messages;

		$txt = '';
		foreach($results as $key => $r) {
			$txt .= "\r\n".'['.$key.']: '.$r;
		}
		JLog::add($txt, $priority, $category);
	}
}